package com.ruoyi.web.controller.pc;


import com.ruoyi.business.domain.WmsStoreRegionLocation;
import com.ruoyi.business.service.IWmsStoreRegionLocationService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 库位管理 Controller
 *
 * @author patton
 * @date 2023-07-16
 */
@RestController
@RequestMapping("/business/storeLocation")
public class WmsStoreLocationController extends BaseController {

    @Autowired
    private IWmsStoreRegionLocationService wmsStoreRegionLocationService;

    /**
     * @Description: 列表
     * @author yunlong
     */
    @ApiOperation(value = "列表")
    @GetMapping("list")
    @CrossOrigin
    public TableDataInfo queryList(WmsStoreRegionLocation info) {
        startPage();
        List<WmsStoreRegionLocation> list = wmsStoreRegionLocationService.selectWmsStoreRegionLocationList(info);
        return getDataTable(list);
    }

    /**
     * @Description: 全部列表
     * @author yunlong
     */
    @ApiOperation(value = "全部列表")
    @GetMapping("queryAllList")
    @CrossOrigin
    public AjaxResult queryAllList(WmsStoreRegionLocation info) {
        List<WmsStoreRegionLocation> list = wmsStoreRegionLocationService.selectWmsStoreRegionLocationList(info);
        return AjaxResult.success(list);
    }

    /**
     * @Description: 详情接口
     * @author yunlong
     */
    @ApiOperation(value = "详情接口")
    @GetMapping("getDetail")
    @CrossOrigin
    public AjaxResult getDetail(WmsStoreRegionLocation info) {
        info = wmsStoreRegionLocationService.selectWmsStoreRegionLocationById(info.getId());
        return AjaxResult.success(info);
    }

    /**
     * 新增
     */
    @Log(title = "新增", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody WmsStoreRegionLocation info)
    {
        WmsStoreRegionLocation obj = wmsStoreRegionLocationService.selectWmsStoreRegionLocationBySn(info.getLocationSn());
        if(obj != null){
            return AjaxResult.error("库位编码已存在");
        }
        info.setCreateBy(getUsername());
        return toAjax(wmsStoreRegionLocationService.insertWmsStoreRegionLocation(info));
    }

    /**
     * 修改
     */
    @Log(title = "修改", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody WmsStoreRegionLocation info)
    {
        WmsStoreRegionLocation obj = wmsStoreRegionLocationService.selectWmsStoreRegionLocationBySn(info.getLocationSn());
        if(obj != null && !obj.getId().equals(info.getId())){
            return AjaxResult.error("库位编码已存在");
        }
        info.setUpdateBy(getUsername());
        return toAjax(wmsStoreRegionLocationService.updateWmsStoreRegionLocation(info));
    }

    /**
     * 删除
     */
    @Log(title = "删除", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    public AjaxResult remove(@RequestBody WmsStoreRegionLocation info)
    {
        wmsStoreRegionLocationService.deleteWmsStoreRegionLocationById(info.getId());
        return AjaxResult.success();
    }

}
